<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
        }
        .box1{
            background: yellow;
        }
        .box2{
            background: blue;
        }
        .box3{
            background: red;
        }
    </style>
</head>
<body>
    <button>按钮一</button><button>按钮二</button><button>按钮三</button>
    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">2</div>
    <script>
        // var obut=document.querySelectorAll(".but")
        // var odiv=document.querySelectorAll(".div")
        var buts = document.querySelectorAll("button")
        var divs = document.querySelectorAll("div")
        buts.forEach(function (item, key) {
            item.onclick = function () {
                divs.forEach(function (div) {
                    div.style.display = "none"
                })
                divs[key].style.display = "block"
            }
        })

    </script>
</body>
</html>